package day19.homework;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Cache {
    private final Map<String, String> cacheMap = new HashMap<>();
    private ReadWriteLock lock = new ReentrantReadWriteLock();

    public void put(String key, String value) {
        lock.writeLock().lock();
        try {
            cacheMap.put(key, value);
        } finally {
            lock.writeLock().unlock();
        }
    }
    public String get(String key) {
        lock.readLock().lock();
        try {
//            return cacheMap.get(key);
            for(Map.Entry<String, String> entry : cacheMap.entrySet()) {
                System.out.println(entry.getKey() + ":" + entry.getValue());
            }
        } finally {
            lock.readLock().unlock();
        }
        return null;
    }
}
